#include "objtable.h"

#include "xmlhelpers.h"

ObjTable::ObjTable() {
}

void ObjTable::Load (rapidxml::xml_document<> & xml) throw(Error) {
	rapidxml::xml_node<> * texels_node = XMLGetNode(xml, XML_TEXELS_NODE);
	rapidxml::xml_node<> * node;
	for (node = XMLGetNode(texels_node, "texel"); node; node = XMLGetSibling(node)) {
		std::string id;
		XMLGetValue(id, node, "id");
		Texel tmp_tex(node);
		tmp_tex.SetTbl(this);
		char idc = id.at(0);

		Add(idc, tmp_tex);
	}
}

void ObjTable::Add(char id, Texel & texel) throw(Error) {
	try {
		insert(std::pair<char, Texel> (id, texel));
	} catch (std::exception & ex) {
		throw(Error("Error while adding texel into ObjTable"));
	}
}

ObjTable::~ObjTable () {
}
